import os.path
def AnalyzeFile(fileName,spacing = 40):    
    inFile = open(fileName);
    size = os.path.getsize(fileName)
    metaFile = open(fileName+".meta",'w')
    unReciprocatedFile = open(fileName+".single",'w')    
    
    'Spacing must be even'
    if(spacing%2==1):
        spacing+=1;
    
    counter = 0
    prev = 0
    placeHolder = 0
    progress= 0;
    'Loop through all the lines'
    while 1:        
        line = inFile.readline()
        'If there is no more to read, break out'
        if(not line):
            break
        
        
        'We really only want the Meta data to be sampled every few, which is where spacing comes in'
        if(counter%spacing == 0):
            metaFile.write(line.strip().split("   ")[0]+":"+str(prev)+"\n")
        counter+=2        
            
        line2 = inFile.readline()
        if(counter%spacing == 0):            
            prev = inFile.tell()
        
        node = line.strip().split("   ")[0]
        if not line2:
            break
        node2 = line2.strip().split('   ')[0]
        done = False
        while node != node2:
            line = line2
            line2 = inFile.readline()
            if not line2:
                done = True
                break
            node = node2
            node2 = line2.strip().split('   ')[0]
        if done:
            break
        
        if not (line.startswith(node+'   0') and line2.startswith(node+'   1')):
            raise Exception(node, line, line2)
        l1 = set(line.strip().split("   ")[3:-1])
        l2 = set(line2.strip().split("   ")[3:-1])
        recip = l1.intersection(l2)
        unReciprocatedFile.write(node+":"+",".join(l1.difference(recip))+"\n");
        if(inFile.tell()-progress>0.1*size):
            progress = inFile.tell()
            print str(progress)+"/"+str(size) +" - "+str(100.0*float(progress)/size)+"%"
        
    inFile.close()
    metaFile.close()      
    unReciprocatedFile.close()  
    print "Done"
    
    
    
    
    
